//
//  ZScrollViewViewController.m
//  LoopImage
//
//  Created by 周成龙 on 2018/3/12.
//  Copyright © 2018年 XZL. All rights reserved.
//

#import "ZScrollViewViewController.h"
#import "ZImageLoopView.h"
@interface ZScrollViewViewController () <ZImageLoopViewDelegate, ZImageLoopViewDataSource>

@property (nonatomic, strong) NSArray *cellInfoArray;
@property (nonatomic, strong) ZImageLoopView *imageLooplView;
@property (nonatomic, assign) NSUInteger pageWidth;
@property (nonatomic, assign) NSUInteger pageHeight;

@end

@implementation ZScrollViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSMutableArray *arr = @[].mutableCopy;
    for (NSInteger i = 0 ; i < 9; i ++) {
        NSString *imageName = [NSString stringWithFormat:@"%02ld.jpg", i + 1];
        [arr addObject:imageName];
    }
    self.cellInfoArray = arr.copy;
    
    _imageLooplView = [[ZImageLoopView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.pageHeight) withDataSource:self withDelegate:self];
    [self.view addSubview:_imageLooplView];
    _imageLooplView.clipsToBounds = YES;
    
    [_imageLooplView reloadData];
}

- (CGSize)sizeForPageInLoopView:(ZImageLoopView *)loopView {
    return CGSizeMake(self.pageWidth, self.pageHeight);
}

- (NSInteger)numberOfPagesInLoopView:(ZImageLoopView *)loopView {
    return self.cellInfoArray.count;
}

- (ZLoopCell *)loopView:(ZImageLoopView *)loopView cellForPageAtIndex:(NSUInteger)index {
    ZLoopCell *cell = [[ZLoopCell alloc] initWithFrame:CGRectMake(0, 0, self.pageWidth - 4, self.pageHeight)];
    cell.imageView.image = [UIImage imageNamed:self.cellInfoArray[index]];
    return cell;
}

- (void)loopView:(ZImageLoopView *)loopView didScrollToPage:(NSInteger)pageNumber {
    NSLog(@"-----%zd", pageNumber);
}

#pragma mark - Setter / Getter
- (NSUInteger)pageWidth {
    return self.view.bounds.size.width * 0.84;
}

- (NSUInteger)pageHeight {
    return self.pageWidth * 0.6;
}

@end
